<html>
<head><meta charset="utf-8"><title>Catching foreign exceptions · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html">Catching foreign exceptions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179248202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179248202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179248202">(Oct 28 2019 at 16:31)</a>:</h4>
<p>After thinking about it for a bit, there's a huge issue with catching foreign exceptions.</p>



<a name="179248308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179248308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179248308">(Oct 28 2019 at 16:31)</a>:</h4>
<p>The exception object is only live inside the <code>catch</code> block. In Rust, this <code>catch</code> block is located entirely within <code>intrinsics::try</code>.</p>



<a name="179248507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179248507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179248507">(Oct 28 2019 at 16:33)</a>:</h4>
<p>Basically if you want to be able to rethrow the foreign exception, this has to be done inside the <code>catch</code> block.</p>



<a name="179248569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179248569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179248569">(Oct 28 2019 at 16:33)</a>:</h4>
<p>Otherwise the only thing you can do is return a "some foreign exception happened" error that you can't rethrow.</p>



<a name="179249539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179249539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179249539">(Oct 28 2019 at 16:40)</a>:</h4>
<p>Sounds like either a new library function or a new syntax construct would be required for useful interaction with foreign exceptions, then.</p>



<a name="179249664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179249664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179249664">(Oct 28 2019 at 16:42)</a>:</h4>
<p>In any case, catching foreign exceptions is currently outside the scope of the project group: <a href="#narrow/stream/210922-wg-ffi-unwind/topic/meeting.20time/near/178413258" title="#narrow/stream/210922-wg-ffi-unwind/topic/meeting.20time/near/178413258">https://rust-lang.zulipchat.com/#narrow/stream/210922-wg-ffi-unwind/topic/meeting.20time/near/178413258</a></p>



<a name="179249858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179249858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179249858">(Oct 28 2019 at 16:43)</a>:</h4>
<p>Well there are some implications: since foreign exceptions allow you to unwind through <code>catch_unwind</code> silently, unsafe code needs to ensure that they do not use <code>catch_unwind</code> to maintain safety and instead use drop guards.</p>



<a name="179250713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179250713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179250713">(Oct 28 2019 at 16:51)</a>:</h4>
<p>That's true. Though since foreign exception behavior in Rust isn't yet defined, <code>catch_unwind</code> should really be thought of as <code>catch_panic</code> (and in my opinion it was misnamed).</p>



<a name="179258874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179258874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179258874">(Oct 28 2019 at 18:12)</a>:</h4>
<p>These are some of the reasons for why I thought that maybe it would be more conservatibe for <code>catch_unwind</code> to abort on foreign exceptions at best</p>



<a name="179271203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179271203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179271203">(Oct 28 2019 at 20:17)</a>:</h4>
<p>This is a really interesting question</p>



<a name="179271229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179271229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179271229">(Oct 28 2019 at 20:18)</a>:</h4>
<p>I think <span class="user-mention" data-user-id="120076">@Kyle Strand</span> that it'd be great to collect notes on <em>this</em> into the repo</p>



<a name="179271388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179271388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179271388">(Oct 28 2019 at 20:19)</a>:</h4>
<p>I am imagining that we should basically have "in progress summaries" on key questions</p>



<a name="179271488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20foreign%20exceptions/near/179271488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20foreign.20exceptions.html#179271488">(Oct 28 2019 at 20:20)</a>:</h4>
<blockquote>
<p>I am imagining that we should basically have "in progress summaries" on key questions</p>
</blockquote>
<p>That seems good as a way of organizing the "discussion summaries" section.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>